package bkeagent

import (
	_ "embed"
	"fmt"
	"os"

	"gopkg.openfuyao.cn/bkeadm/pkg/executor/k8s"
	"gopkg.openfuyao.cn/bkeadm/pkg/global"
)

var (
	//go:embed bkeagent.yaml
	bkeAgent []byte
)

func InstallBKEAgentCRD() (err error) {
	if global.K8s == nil {
		global.K8s, err = k8s.NewKubernetesClient("")
		if err != nil {
			return err
		}
	}
	bkeAgentFile := fmt.Sprintf("%s/tmpl/bkeagent.yaml", global.Workspace)
	err = os.WriteFile(bkeAgentFile, bkeAgent, 0644)
	if err != nil {
		return err
	}

	err = global.K8s.InstallYaml(bkeAgentFile, map[string]string{}, "")
	if err != nil {
		return err
	}
	return nil
}
